<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<%@ include file="admin_Header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add Product</title>
</head>
<body>
<%
	if ((request.getParameter("productName") != null) &&
	    (request.getParameter("productUnit") != null) &&
		(request.getParameter("productQuantityPerUnit") != null))
	{
	    out.println("Adding product " + request.getParameter("productName"));
		try
		{
			String productName = request.getParameter("productName");
			String productUnit = request.getParameter("productUnit");
			Double productQuantityPerUnit = Double.parseDouble(request.getParameter("productQuantityPerUnit"));
			Product product = new Product();
			product.setProductName(productName);
			product.setProductUnit(productUnit);
			product.setProductQuantityPerUnit(productQuantityPerUnit);
			product.setProductImage(null);
			iproducts.AddProduct(product);
			Product verifyProduct = iproducts.FindProduct(product.getProductName(), product.getProductUnit(), product.getProductQuantityPerUnit());
			if ((verifyProduct.getProductName().equals(productName)) &&
				(verifyProduct.getProductQuantityPerUnit().equals(productQuantityPerUnit)) &&
				(verifyProduct.getProductUnit().equals(productUnit)))
			{
				out.println("\nProduct added successfully");
			}
			else
			{
				out.println("\nSomething went wrong, please check");
			}
		}
		catch(Exception e)
		{
			throw new Exception("Error in connecting to database, please contact your administrator");
		}
	}
%>
<center>
	<h1>Product Compare Application</h1>
	<button id="List" onclick="window.location.href='admin_ListProducts.jsp'">Get Product List</button>
	<button id="AddProduct" onclick="window.location.href='admin_AddProduct.jsp'">Add New Product</button>
	<button id="AddSuperMarket" onclick="window.location.href='admin_AddSupermarket.jsp'">Add New SuperMarket</button>
	<button id="ManageSuperMarket" onclick="window.location.href='admin_ManageSupermarket.jsp'">Manage Supermarket</button>
	<button id="DeleteProduct" onclick="window.location.href='admin_DeleteProduct.jsp'">Delete Product</button>
	<button id="DeleteSupermarket" onclick="window.location.href='admin_DeleteSupermarket.jsp'">Delete Supermarket</button>
</center>
<center>
<br><br>
<form action="admin_AddProduct.jsp" method="post">
<table border=1>
	<tr>
		<th colspan=2>Add Product</th>
		<tr>
			<td>
				<label>Product Name</label>
			</td>
			<td> 
				<input type="Text" name="productName">	
			</td> 
		</tr>
		<tr>
			<td>
				<label>Unit</label>
			</td>
			<td>
				<input type="Text" name="productUnit">	
			</td> 
		</tr>
		<tr>	
			<td>
				<label>Quantity Per Unit</label>
			</td>
			<td>
				<input type="Text" name="productQuantityPerUnit">	
			</td>
		</tr>
		<tr>
			<td>
				<label>Image</label>
			</td>
			<td>
				<input type="File" name="productImage">	
			</td>
		</tr>
		<tr>
		<td colspan=2 align="center">
			<button type="submit">Submit</button>
		</td>
	</tr>
</table>
</form>
</center>
</body>
</html>